package com.caioweb.osa.dao;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.caioweb.osa.modelo.Branch;
import com.caioweb.osa.transacoes.interceptor.Transactional;



public class BranchDAO implements Serializable{
	@Inject
	private EntityManager em;

	@Transactional
	public List<Branch> existeBranch(String  nome){
	 Query query = em.createQuery("from Branch where nome = :nome");
	    query.setParameter("nome", nome);
	    return (List<Branch>) query.getResultList();
	}
	@Transactional
	public boolean existeUrl(String url){
		String jpql = "select b from Branch b where b.url = :url";
		Query query = em.createQuery(jpql);
		query.setParameter("url", url);
		
		return !query.getResultList().isEmpty();
	}
}